package com.bbf.springbootdemo.feature;

import com.bbf.springbootdemo.util.BaseUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

/**
 * 全局配置类
 * @author BBF
 */
@ConfigurationProperties(prefix = "bbf")
@Validated
public class CustomProperties extends BaseBean {
  private static final long serialVersionUID = -3823804773124959970L;

  private String author;
  private String showMessage;

  public String getAuthor() {
    return author;
  }

  public void setAuthor(String author) {
    this.author = author;
  }

  public String getShowMessage() {
    return showMessage;
  }

  public void setShowMessage(String showMessage) {
    this.showMessage = convertToUtf8(showMessage);
  }

  public static boolean isBlank(String str){
    return StringUtils.isBlank(str);
  }

  public static boolean isNoneBlank(String str){
    return StringUtils.isNoneBlank(str);
  }

  /**
   * 将properties文件中出现的中文转换为英文
   * @param msg 中文乱码
   * @return 正确的中文
   */
  private static String convertToUtf8(String msg) {
    return new String(msg.getBytes(BaseUtil.CHARSET_ISO859), BaseUtil.CHARSET_UTF8);
  }
}
